package com.atguigu.admin.controller;

import com.atguigu.admin.bean.Admin;
import com.atguigu.admin.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class AdminController {




    @Autowired
    private AdminService adminService;

    @RequestMapping("/delete")
    public String delete(@RequestParam("id") Integer id){
        adminService.deleteById(id);

        return "redirect:/list";



    }

    @RequestMapping("/list")
    public String getList(Map<String,Object> map){
        List<Admin> list = adminService.list();

        map.put("admins",list);
        return "table";
    }

    @ResponseBody
    @RequestMapping("/acct")
    public Admin getAdminById(@RequestParam("id") Integer id){

        Admin admin = adminService.getById(id);

        return admin;


    }
}
